import { Ref } from "vue";
import ImageLayer from "ol/layer/Image";
import ImageArcGISRest from "ol/source/ImageArcGISRest";
import { Map } from "ol";

export function useChangshaLayer(map: Ref<Map | null>) {
  const loadChangshaLayer = () => {
    if (!map.value) return;

    const url =
      "http://172.24.10.17:18300/1548461356/geoscene/rest/services/cim/sl_xzqh/MapServer";

    const imageLayer = new ImageLayer({
      source: new ImageArcGISRest({
        ratio: 1,
        params: {
          LAYERS: "show:0,1,2,3,4,5,6",
          FORMAT: "PNG32",
          TRANSPARENT: true,
          key: "d58b17638488401192fb1ea7929ea795",
        },
        url: url,
      }),
    });

    map.value.addLayer(imageLayer);
  };

  return {
    loadChangshaLayer,
  };
}
